package 斗地主游戏1控制台版;

import java.util.ArrayList;
import java.util.Collections;

public class PokerGame1 {
    //静态代码块
    //特点：随着类的加载而加载，而且只执行一次
    static ArrayList<String> list = new ArrayList<>();
    ArrayList<String> lord = new ArrayList<>();
    ArrayList<String> player1 = new ArrayList<>();
    ArrayList<String> player2 = new ArrayList<>();
    ArrayList<String> player3 = new ArrayList<>();

    //准备牌
    static {
        //"♣", "♦", "♥" ,"♠"
        String[] color = {"♣", "♦", "♥", "♠"};
        String[] number = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
        //牌盒
        for (String c : color) {
            //c:表示每一种花色
            for (String n : number) {
                //n ：表示每一个数字
                list.add(c + n);
            }
        }
        Collections.addAll(list, "小王", "大王");


    }

    public PokerGame1() {
        //洗牌
        Collections.shuffle(list);
        //发牌
        //遍历牌盒得到每一张牌
        for (int i = 0; i < list.size(); i++) {
            String poker = list.get(i);
            if (i <= 2) {
                lord.add(poker);
                continue;
            }
            //给三个玩家轮流发牌
            if (i % 3 == 0) {
                player1.add(poker);
            } else if (i % 3 == 1) {
                player2.add(poker);
            }
            else {
                player3.add(poker);
            }

        }

        //看牌
        lookPoker("玩家一", player1);
        lookPoker("玩家二", player2);
        lookPoker("玩家三", player3);
        lookPoker("底牌", lord);

    }


    //参数一：玩家名字
    //参数二：每位玩家的牌
    public void lookPoker(String name, ArrayList<String> list) {
        System.out.print(name + ": ");
        for (String poker : list) {
            System.out.print(poker + "  ");
        }
        System.out.println();
    }


}
